package com.example.wxchatdemo.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

//转换json
public  class TransJSONtoUsers {
    private String argss;
    public TransJSONtoUsers() {

    }

    public TransJSONtoUsers(String argss) {
    this.argss=argss;
    }

 public    List<Map<String,String>> ttransJSON(String args) {
        List<Map<String,String>> list = new ArrayList<>();
        Map map=new HashMap<String,String >();


        String jsonArray=args;
        StringBuffer sb=new StringBuffer();
        //需要使用的JSON的parseArray方法，将jsonArray解析为object类型的数组
        JSONArray objects = JSON.parseArray(jsonArray);
        int i=0;
        // for(int i=0;i<objects.size();i++){
     System.out.println("onjiect的数量"+objects.size());
        while (i<objects.size()){
            Map map2=new HashMap<String,String >();
            //通过数组下标取到object，使用强转转为JSONObject，之后进行操作
            JSONObject object = (JSONObject) objects.get(i);
            String id = object.getString("id");
            String aname = object.getString("aname");
            String aspeak= object.getString("aspeak");
            String anumber= object.getString("anumber");
            String lasttime= object.getString("lasttime");
            String myid= object.getString("myid");
            String friends= object.getString("friends");
            //System.out.println("TranJson方法结果集"+"id="+id+"---myid--="+myid+"--youid="+youid+"--time="+times+"==="+content);
           // System.out.println(id+"==="+aname+"==="+aspeak+"==="+anumber+"=="+lasttime+"==="+myid+"===="+friends);
            //把数据放入map中
            map2.put("id",id);
            map2.put("aname",aname);
            map2.put("aspeak",aspeak);
            map2.put("anumber",anumber);
            map2.put("lasttime",lasttime);
            map2.put("myid",myid);
            map2.put("friends",friends);
            list.add(map2);
            i++;
        }
        return list;



    }


}
